require("common-css");
require("header-css");
require("custom-css");
let baseInfo = {
  pageNumber: null
};

import {
  loader
} from "hobbit";
import {
  GetCultureNews
} from "request";
import {
  initCommon
} from "common";
const template = require("template");

const app = {
  init() {
    this.bind();
    initCommon();
    baseInfo.pageNumber = 2;
    app.currNum = 2;
    app.category = 645;
  },
  bind() {
    $(".custom_menu li.active a span").css("color", "#FF7B6C");
    $(".custom_menu li").click(function() {
      $(this).addClass("active").siblings("li").removeClass("active");
      var text = $(this).find("a span");
      app.category = $(this).find("a").attr("data-category");
      if (text.html() == "康藏民俗") {
        text.css("color", "#FF7B6C");
        $(this).siblings("li").find("a span").css("color", "#9A9A9A");
      } else if (text.html() == "康藏人文") {
        text.css("color", "#ED48FA");
        $(this).siblings("li").find("a span").css("color", "#9A9A9A");
      } else if (text.html() == "演出会展") {
        text.css("color", "#2EE5CF");
        $(this).siblings("li").find("a span").css("color", "#9A9A9A");
      } else if (text.html() == "康巴文学") {
        text.css("color", "#176DFE");
        $(this).siblings("li").find("a span").css("color", "#9A9A9A");
      }
      $("#j-product").html("");
      app.currNum = 1;
      app.loadMore();
    });

    //加载更多
    $('.see-more').on('click', function() {
      app.loadMore();
    });
  },
  loadMore() {
    loader.show({
      text: "加载中..."
    });
    var params = {};
    params.pageIndex = app.currNum;
    params.category = app.category;
    params.pageSize = 10;
    GetCultureNews(params, (res) => {
      if (res.hasValue == "true") {
        if (res.data) {
          $("#j-product").append(template("goods-list-temp", {
            list: res.data
          }));
        }
        if (res.data.length < 10) {
          $('.see-more').hide();
        }
        app.currNum++;
      } else {
        $('.see-more').hide();
      }
      loader.close();
    });
  }
}
app.init();